﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Frame.Lib.Core.User;
using Frame.Lib.Core.Role;
using Frame.Lib.Core.Dept;
using Frame.Lib.Core.Tree;
using Frame.Lib.Utilities;


namespace Jzy.Web.WorkFlow.Node
{
    public partial class SelectDefaultUser : PageSelectTree
    {
        

        private string RoleIDs
        {
            get
            {
                return Request["RoleIDs"];
            }
        }

        private string UserIDs
        {
            get
            {
                return Request["UserIDs"];
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindTree();
                tvList.Attributes.Add("onclick", "SingleSelect()");
            }
        }

        private void BindTree()
        {
            UserBO user = new UserBO();
            RoleBO role = new RoleBO();

            List<int> lstUserIDs = new List<int>();
            DeptBO.SplitDeptUser(UserIDs, null, lstUserIDs);

            List<UserInfo> list = user.GetList(lstUserIDs).ToList();
            List<UserInfo> list2 = user.GetListByRoleIDs(RoleIDs);


            //需要去重
            list.AddRange(list2.Where(data => !(from tmp in list
                                                select tmp.ID).Contains(data.ID)).ToList());
            foreach(UserInfo info in list)
            {
                TreeNode node = new TreeNode();
                node.ShowCheckBox = false;
                node.Text = TreeBO<TreeInfo>.GetCheckBoxNode(info.ID, info.Name, null);

                node.SelectAction = TreeNodeSelectAction.None;

                tvList.Nodes.Add(node);
            }

            List<int> lstSelectIDs = StrUtil.SplitToInt(RestoreIDs);

            JSUtil.SetTreeSelect(lstSelectIDs);
        }
    }
}
